package com.fy.qu.controller;

import com.fy.core.dto.PageDto;
import com.fy.core.vo.ApiRest;
import com.fy.core.vo.PageResult;
import com.fy.qu.dto.QuSearchDto;
import com.fy.qu.entity.Qu;
import com.fy.qu.service.QuService;
import com.fy.qu.dto.QuAddDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 问题题目 前端控制器
 * </p>
 *
 * @author hxd
 * @since 2023-06-12
 */
@RestController
@CrossOrigin
@RequestMapping("/qu")
public class QuController {

    @Autowired
    private QuService quService;

    @PostMapping("page")
    public PageResult<Qu> findPage(@RequestBody PageDto<QuSearchDto> pageDto){
        return quService.findPage(pageDto);
    }

    @PostMapping("save")
    public ApiRest save(@RequestBody QuAddDto quAddDto){
        return quService.save(quAddDto);
    }

    @GetMapping("findById/{quId}")
    public ApiRest findById(@PathVariable("quId") String quId){
        return quService.findById(quId);
    }

    @PostMapping("update")
    public ApiRest update(@RequestBody QuAddDto quAddDto){
        return quService.update(quAddDto);
    }

    @GetMapping("delete/{quId}")
    public ApiRest delete(@PathVariable("quId") String quId){
        return quService.delete(quId);
    }

    @PostMapping("delete/batchDelete")
    public ApiRest batchDelete(@RequestBody List<Qu> qus){
        System.out.println("qus = " + qus);

        return quService.batchDelete(qus);

    }

}
